package com.ruix.app.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.ruix.app.R;
import com.ruix.app.model.Comment;
import com.ruix.app.model.PostsCard;
import com.ruix.app.util.CopyUtil;
import com.ruix.app.util.ToastUtil;

/**
 * Created by hadexs on 2017/4/30.
 */

public class DeleteCommentDialog  extends Dialog implements View.OnClickListener{


    private PostsCard postsCard;
    private Comment comment;
    private int position;
    private DeleteCommentListener listener;
    private TextView deleteAction;
//    private  

    public DeleteCommentDialog(Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.dialog_delete_comment);
        setCanceledOnTouchOutside(true);
        //初始化界面控件
        //初始化界面控件的事件
        initEvent();

        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.gravity = Gravity.CENTER;
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;//宽高可设置具体大小
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);

    }

    private void initEvent(){
        findViewById(R.id.tv_copy_comment).setOnClickListener(this);
        deleteAction = (TextView) findViewById(R.id.tv_delete_comment);
        deleteAction.setOnClickListener(this);
        findViewById(R.id.tv_cancel_action).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_copy_comment:
                dismiss();
                CopyUtil.clipboardCopy(getContext(),comment.getContent());
                ToastUtil.showNewSuccessMsg("已复制");
                break;
            case R.id.tv_delete_comment:
                dismiss();
                if (listener != null){
                    listener.deleteCommentPositive(postsCard,position);
                }
                break;
            case R.id.tv_cancel_action:
                dismiss();
                break;
        }
    }

    public void setListener(DeleteCommentListener listener) {
        this.listener = listener;
    }



    public void show(PostsCard item, int commentPosition){
        if (item != null) {
            this.postsCard = item;
            this.position = commentPosition;
            this.comment = item.getComments().get(commentPosition);
            show();
        }
    }


    public interface DeleteCommentListener{
        void deleteCommentPositive(PostsCard item,int commentPosition) ;
    }
}
